// import WXBizDataCrypt from '@/utils/WXBizDataCrypt.js';
//用户信息登录
export function getUserInfo(event: any) {
	if (event.detail.errMsg == 'getUserInfo:ok') {
		return new Promise((resolve, reject) => {
			uni.getUserInfo({
				desc: '获取个人信息',
				withCredentials: false,
				lang: 'zh_CN',
				timeout: 10000,
				success(info: any) {
					uni.login({
						provider: 'weixin', //声明小程序类型
						success: (loginRes) => {
							resolve({ ...loginRes, ...info });
						},
						fail: (loginErr: any) => {
							reject(loginErr);
						},
					});
				},
			});
		});
	}
}

//手机号授权登录
export function getPhoneNumber(event: any) {
	if (event.errMsg == 'getPhoneNumber:ok') {
		return new Promise((resolve, reject) => {
			//检查登录是否过期
			uni.checkSession({
				success: (res) => {
					if (res.errMsg == 'checkSession:ok') {
						resolve(event);
					}
				},
				fail: (error: any) => {
					reject(error);
				},
			});
		});
	}
}

// export function mobile(res, detail) {
// appid: '', //你的小程序的APPID
// secret: '', //你的小程序秘钥secret,
// js_code: res.code, //wx.login 登录成功后的code
// grant_type: 'authorization_code' //此处为固定值
// 接口请求成功后调取
// let pc = new WXBizDataCrypt(appId, request.data.session_key);
// let data = pc.decryptData(detail.encryptedData, detail.iv);
// 获取手机号 然后调取uni.login登录
// }
